package com.sleep.drug_traceability.controller;

import com.sleep.drug_traceability.service.SearchService;
import com.sleep.drug_traceability.vo.Result;
import com.sleep.drug_traceability.vo.params.OneParam;
import com.sleep.drug_traceability.vo.params.SearchManParam;
import com.sleep.drug_traceability.vo.params.SearchSelParam;
import com.sleep.drug_traceability.vo.params.TwoParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Sleep-6000
 * @date 2022/4/28
 */
@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 药品生产商的药品溯源页面，获取药品生产数据
     *
     * @param searchManParam 溯源限制条件
     * @return 药品生产数据
     */
    @PostMapping("mand")
    public Result searchManDrug(@RequestBody SearchManParam searchManParam) {
        return searchService.searchManDrug(searchManParam);
    }

    /**
     * 药品生产商的药品溯源页面，获取药品运输数据
     *
     * @param searchTraParam 溯源限制条件
     * @return 药品运输数据
     */
    @PostMapping("trad")
    public Result searchTraDrug(@RequestBody SearchManParam searchTraParam) {
        return searchService.searchTraDrug(searchTraParam);
    }

    /**
     * 销售商的药品溯源页面，获取药品购买数据
     *
     * @param searchSelParam 溯源限制条件
     * @param token          token
     * @return 药品购买数据
     */
    @PostMapping("seld")
    public Result searchSelDrug(@RequestBody SearchSelParam searchSelParam,
                                @RequestHeader("Authorization") String token) {
        return searchService.searchSelDrug(searchSelParam, token);
    }

    /**
     * 销售商的药品溯源页面，获取消费者数据
     *
     * @param searchConParam 溯源限制条件
     * @param token          token
     * @return 消费者数据
     */
    @PostMapping("cond")
    public Result searchConDrug(@RequestBody SearchSelParam searchConParam,
                                @RequestHeader("Authorization") String token) {
        return searchService.searchConDrug(searchConParam, token);
    }

    /**
     * 监管部门的药品溯源页面，获取药品生产数据
     *
     * @param param 药品溯源编码
     * @return 药品生产数据
     */
    @PostMapping("manTable")
    public Result getManTable(@RequestBody OneParam param) {
        return searchService.getManTable(param);
    }

    /**
     * 监管部门的药品溯源页面，获取药品运输数据
     *
     * @param param 药品溯源编码
     * @return 药品运输数据
     */
    @PostMapping("traTable")
    public Result getTraTable(@RequestBody OneParam param) {
        return searchService.getTraTable(param);
    }

    /**
     * 监管部门的药品溯源页面，获取销售商的药品购买数据
     *
     * @param param 药品溯源编码
     * @return 销售商的药品购买数据
     */
    @PostMapping("selTable")
    public Result getSelTable(@RequestBody OneParam param) {
        return searchService.getSelTable(param);
    }

    /**
     * 监管部门的药品溯源页面，获取消费者数据
     *
     * @param param 药品溯源编码
     * @return 消费者数据
     */
    @PostMapping("conTable")
    public Result getConTable(@RequestBody OneParam param) {
        return searchService.getConTable(param);
    }

    /**
     * 获取药品溯源编码
     * @param twoParam twoParam
     * @return 药品溯源编码
     */
    @PostMapping("searchCode")
    public Result searchCode(@RequestBody TwoParam twoParam) {
        return searchService.searchCode(twoParam);
    }
}
